/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var webjs = {
    isConnectedFacebook: false,
    callbackscript: "",
    loginFacebook:function(){
        webjs.blockUIMessageBox("Kopler til Facebook");
        FB.login(function(response) {
            if (response.authResponse) {
                var accessToken = response.authResponse.accessToken;
                var userID = response.authResponse.userID;
                jQuery.post("loginfacebook.php", {
                    accessToken: accessToken,
                    userID: userID
                }, function(data){
                    jQuery.unblockUI();
                    var r = eval("(" + data + ")");
                    if(r.status == "1") {
                        webjs.isConnectedFacebook = true;
                        if(webjs.callbackscript != "") {
                            eval(webjs.callbackscript);
                            webjs.callbackscript = "";
                        } else {
                            window.location.href = r.redirect;
                        }
                    }
                });
            } else {
                webjs.blockUIMessageBox("Beklager, kunne ikke kople mot Facebook.");

                setTimeout(jQuery.unblockUI, 2000);

                return false;
            }
        }, {scope: 'email,user_about_me,user_birthday,publish_stream,offline_access'});

    },
    blockUIMessageBox: function(message) {
        jQuery.blockUI({message: message,
            css: {
            border: 'none',
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: .5,
            color: '#fff'
        }});
        jQuery('.blockOverlay').attr('title','Click to unblock').click(jQuery.unblockUI);
    }
};

